#version 120
uniform float sinetime;
uniform sampler2D diffuseTex;
uniform sampler2D normalTex;
varying vec3 light;
varying vec3 color;
varying vec2 texCoord;

varying vec3 T;
varying vec3 B;
varying vec3 N;
void main()
{
  vec4 normalDir = 2.0*texture2D(normalTex, texCoord)-1.0;
  normalDir.w = 1.0;

  vec4 Kd = texture2D(diffuseTex, texCoord);
  vec4 Ka = Kd*0.1;

  mat3 TBN = mat3(normalize(T), normalize(B), normalize(N));
  vec4 trueNormal = vec4(TBN*normalDir.xyz, 1.0);
  vec4 diffuse = Kd*max(0.0, dot(trueNormal.xyz, normalize(light)));
  gl_FragColor = Ka+diffuse;
}

